use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "cms_category")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    /// 上级目录
    #[sea_orm(indexed)]
    pub p_id: i32,
    /// 左值
    #[sea_orm(indexed)]
    pub lt: i32,
    /// 右值
    #[sea_orm(indexed)]
    pub rt: i32,
    /// 层级
    pub lv: i32,
    /// 名称
    pub name: String,
    /// 描述
    pub description: String,
    /// 图标
    pub icon: String,
    /// 别名
    pub alias: String,
    /// 状态(0:未启用,1:启用)
    pub status: i8,
    pub created_at: chrono::NaiveDateTime,
    pub updated_at: chrono::NaiveDateTime,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    // #[sea_orm(
    //     belongs_to = "super::cms_article_category::Entity",
    //     from = "Column::Id",
    //     to = "super::cms_article_category::Column::CategoryId",
    //     on_update = "Restrict",
    //     on_delete = "Restrict"
    // )]
    // ArticleCategory,
}

impl Related<super::cms_article::Entity> for Entity {
    fn to() -> RelationDef {
        super::cms_article_category::Relation::CmsArticle.def()
    }

    fn via() -> Option<RelationDef> {
        Some(
            super::cms_article_category::Relation::CmsCategory
                .def()
                .rev(),
        )
    }
}

impl ActiveModelBehavior for ActiveModel {}
